package com.youhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.mapper.BShareGroupHouseMapper;
import com.youhome.model.BShareGroupHouse;
import com.youhome.service.ShareGroupHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by chen365 on 2018/09/18.
 */
@Service
public class ShareGroupHouseServiceImpl implements ShareGroupHouseService {
    @Autowired
    private BShareGroupHouseMapper bShareGroupHouseMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return bShareGroupHouseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(BShareGroupHouse record) {
        record.setCtime(new Date());
        return bShareGroupHouseMapper.insert(record);
    }

    @Override
    public int insertSelective(BShareGroupHouse record) {
        record.setCtime(new Date());
        return bShareGroupHouseMapper.insertSelective(record);
    }

    @Override
    public BShareGroupHouse selectByPrimaryKey(Long id) {
        return bShareGroupHouseMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(BShareGroupHouse record) {
        return bShareGroupHouseMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(BShareGroupHouse record) {
        return bShareGroupHouseMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<BShareGroupHouse> selectByBean(Integer pageNumber, Integer pageSize, BShareGroupHouse record) {
        if (StringUtils.isEmpty(pageNumber) || pageNumber < 1) {
            pageNumber = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNumber, pageSize);
        List<BShareGroupHouse> bShareGroupHouses = bShareGroupHouseMapper.selectByBean(record);
        return new PageInfo<>(bShareGroupHouses);
    }
}
